﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wp7LLS
{
    // code taken from http://stackoverflow.com/questions/9117597/how-to-group-japanese-and-other-non-latin-names-in-longlistselector
    public static class JapanesePhoneticSupport
    {
        const int KatakanaStartCode = 0x30A0;
        const int HiraganaStartCode = 0x3040;
        const int HiraganaEndCode = 0x309F;

        public static char GetGroupChar(string name)
        {
            // Check for null/blank
            // Check for numbers, etc

            char firstChar = name[0];
            int firstCharCode = (int)firstChar;

            bool isHiragana = (HiraganaStartCode <= firstCharCode &&
                firstCharCode <= HiraganaEndCode);

            if (isHiragana)
            {
                char katakanaChar = (char)(firstCharCode +
                    (KatakanaStartCode - HiraganaStartCode));

                return katakanaChar;
            }

            return Char.ToLowerInvariant(firstChar);
        }
    }
}
